package com.revenant.driver.ui.activity;

import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.revenant.driver.R;
import com.revenant.driver.base.BaseActivity;
import com.revenant.driver.bean.ShipperBean.FaPiaoDetailBean;
import com.revenant.driver.bean.ShipperBean.MyGoodsDetailBean;
import com.revenant.driver.utils.GsonUtil;
import com.revenant.driver.utils.SPUtils;

import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.revenant.driver.utils.Constants.Detail_Goods_Publish_Or_closed;
import static com.revenant.driver.utils.Constants.Fa_Piao_Write_Detail;

public class MyGoodsDetailActivity extends BaseActivity {
    @BindView(R.id.strat_place)
    TextView     stratPlace;
    @BindView(R.id.end_place)
    TextView     endPlace;
    @BindView(R.id.car_num)
    TextView     carNum;
    @BindView(R.id.car_type)
    TextView     carType;
    @BindView(R.id.car_pho)
    TextView     carPho;
    @BindView(R.id.car_name)
    TextView     carName;
    @BindView(R.id.show_driver_info)
    LinearLayout showDriverInfo;
    @BindView(R.id.big_start)
    TextView     bigStart;
    @BindView(R.id.big_end)
    TextView     bigEnd;
    private String data;
    private int    type = 0;

    private List<String> urlist = Arrays.asList(Detail_Goods_Publish_Or_closed, Fa_Piao_Write_Detail);

    @Override
    public int getContentViewResId() {
        return R.layout.activity_goods_detail;
    }

    @Override
    public void initView() {
        setcenterTitle("空车详情");
        Bundle bundle = getIntent().getExtras(); //得到传过来的bundle

        data = bundle.getString("goods_id");
        type = bundle.getInt("goods_type", 0);
    }

    @Override
    public void leftbarclick() {
        super.leftbarclick();
        finish();
    }

    @Override
    public void initData() {
        getGoodsDetail(data);
    }

    private void getGoodsDetail(String dataid) {
        OkGo.<String>get(urlist.get(type))

                .params("id", dataid)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        switch (type) {
                            case 0:
                                MyGoodsDetailBean detailBean = GsonUtil.parseJsonWithGson(response.body(), MyGoodsDetailBean.class);
                                if (detailBean.getCode().equals("0")) {
                                    bigStart.setText(detailBean.getData().getInfo().getLoading());
                                    bigEnd.setText(detailBean.getData().getInfo().getUnload());
                                    stratPlace.setText(detailBean.getData().getInfo().getLoadingDetail());
                                    endPlace.setText(detailBean.getData().getInfo().getUnloadingDetail());
                                    carName.setText(detailBean.getData().getInfo().getName());

                                }
                                break;
                            case 1:

                                FaPiaoDetailBean detailsBean = GsonUtil.parseJsonWithGson(response.body(), FaPiaoDetailBean.class);
                                if (detailsBean.getCode().equals("0")) {
                                    stratPlace.setText(detailsBean.getData().getAddress());
                                    endPlace.setText(detailsBean.getData().getAddressee());
                                }
                                break;
                        }

                    }
                });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
